package com.hotel.config.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 个人中心优惠劵延时队列(双消息队列)
 * 优惠劵过期(双消息队列)
 */
@Configuration
public class PersonalCouponWebSocketDirectConfig {
    // 普通交换机(个人中心优惠劵)(websocket监听)
    public static final String NORMAL_PERSON_COUPON_WEBSOCKET_EXCHANGE = "normal_person_coupon_websocket_exchange";
    // 普通队列名称(个人中心优惠劵)(websocket监听)
    public static final String NORMAL_PERSON_COUPON_WEBSOCKET_QUEUE = "normal_person_coupon_websocket_queue";
    // 个人中心优惠劵绑定Key(websocket监听)
    public static final String NORMAL_PERSON_COUPON_WEBSOCKET_KEY = "normal_person_coupon_websocket_key";
    //个人中心优惠劵绑定Bean(websocket监听)
    public static final String NORMAL_PERSON_COUPON_KEY_WEBSOCKET_BEAN = "normal_person_coupon_key_websocket_bean";

    // 死信交换机(个人中心优惠劵)(websocket监听)
    public static final String DEAD_PERSON_COUPON_WEBSOCKET_EXCHANGE = "dead_person_coupon_websocket_exchange";
    // 死信队列名称(个人中心优惠劵)(websocket监听)
    public static final String DEAD_PERSON_COUPON_WEBSOCKET_QUEUE = "dead_person_coupon_websocket_queue";
    // 死信个人中心优惠劵绑定Key(websocket监听)
    public static final String DEAD_PERSON_COUPON_WEBSOCKET_KEY = "dead_person_coupon_websocket_key";
    //死信个人中心优惠劵绑定Bean(websocket监听)
    public static final String DEAD_PERSON_COUPON_KEY_WEBSOCKET_BEAN = "dead_person_coupon_key_websocket_bean";

    /**
     * 普通交换机(个人中心优惠劵)(websocket监听)
     * @return
     */
    @Bean(NORMAL_PERSON_COUPON_WEBSOCKET_EXCHANGE)
    public DirectExchange createNormalPersonCouponWebSocketExchange(){
        return new DirectExchange(NORMAL_PERSON_COUPON_WEBSOCKET_EXCHANGE,true,false);
    }

    /**
     * 普通队列名称(个人中心优惠劵)(websocket监听)
     * @return
     */
    @Bean(NORMAL_PERSON_COUPON_WEBSOCKET_QUEUE)
    public Queue createNormalPersonCouponWebSocketQueue(){
        Map<String, Object> map = new HashMap<>();
        map.put("x-dead-letter-exchange",DEAD_PERSON_COUPON_WEBSOCKET_EXCHANGE);
        map.put("x-dead-letter-routing-key",DEAD_PERSON_COUPON_WEBSOCKET_KEY);
        return new Queue(NORMAL_PERSON_COUPON_WEBSOCKET_QUEUE,true,false,false,map);
    }

    /**
     * 普通队列绑定交换机(个人中心优惠劵)(websocket监听)
     * @return
     */
    @Bean(NORMAL_PERSON_COUPON_KEY_WEBSOCKET_BEAN)
    public Binding bindNormalPersonCouponWebSocket(){
        return BindingBuilder.bind(createNormalPersonCouponWebSocketQueue()).to(createNormalPersonCouponWebSocketExchange()).with(NORMAL_PERSON_COUPON_WEBSOCKET_KEY);
    }

    /**
     * 死信交换机(个人中心优惠劵)(websocket监听)
     * @return
     */
    @Bean(DEAD_PERSON_COUPON_WEBSOCKET_EXCHANGE)
    public DirectExchange createDeadPersonCouponWebSocketExchange(){
        return new DirectExchange(DEAD_PERSON_COUPON_WEBSOCKET_EXCHANGE,true,false);
    }

    /**
     * 死信队列(个人中心优惠劵)(websocket监听)
     * @return
     */
    @Bean(DEAD_PERSON_COUPON_WEBSOCKET_QUEUE)
    public Queue createDeadPersonCouponWebSocketQueue(){
        return new Queue(DEAD_PERSON_COUPON_WEBSOCKET_QUEUE,true);
    }

    /**
     * 绑定死信交换机(个人中心优惠劵)(websocket监听)
     * @return
     */
    @Bean(DEAD_PERSON_COUPON_KEY_WEBSOCKET_BEAN)
    public Binding bindDeadPersonCouponWebSocket(){
        return BindingBuilder.bind(createDeadPersonCouponWebSocketQueue()).to(createDeadPersonCouponWebSocketExchange()).with(DEAD_PERSON_COUPON_WEBSOCKET_KEY);
    }

}
